const Service = require('egg').Service;

class CountryService extends Service {
    // 查看数据
    async index() {
        let countryList = await this.app.model.Country.findAll({});
        return countryList
    }
    // 添加数据
    async create() {
        let name = this.ctx.request.body.name;
        await this.app.model.Country.create({
            name:name
        })
        let countryList = await this.app.model.Country.findAll({});
        return countryList
    }
    // 删除数据
    async destroy(){
        let id = this.ctx.params.id;
        await this.app.model.Country.destroy({
            where:{
                id:id
            }
        })
        let countryList = await this.app.model.Country.findAll({});
        return countryList
    }
    // 修改数据
    async update(){
        let name = this.ctx.request.body.name;
        let id = this.ctx.params.id;
        await this.app.model.Country.update({name:name},{
            where:{
                id:id
            }
        })
        let countryList = await this.app.model.Country.findAll({});
        return countryList
    }
}

module.exports = CountryService;
